FROM harbor.antiy.cn/mobile/ztp/ztp-api/build_base_arch

ADD ops/docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh

ENV MODULE_DIR="/opt/ztp-api"
ENV MODULE_DIR_BAK="/opt/ztp-api-bak"
ENV MODULE_LOG_DIR="/var/log/supervisord"
ENV MODULE_SETTINGS_FILE="/etc/ztp-api/env"

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["supervisord", "-c", "/opt/ztp-api/supervisord.conf"]

COPY . $MODULE_DIR_BAK

RUN --mount=type=cache,target=/root/.cache/pip CFLAGS=-std=c99 pip3.7 install -r ${MODULE_DIR_BAK}/requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
RUN sed -i 's/if self.connection:/if self.connection is not None:/g' /opt/python3/lib/python3.7/site-packages/djongo/base.py
# fix djongo 1.2.32 run python3 manage.py makemigrations error in djongo
# djongo 1.2.38 fix the error but with django == 2.2.1 and 2.1.3 error: Cannot use MongoClient after close
# and djongo 1.2.32 no error: Cannot use MongoClient after close
RUN sed -i 's/.collection_names(False)/.list_collection_names()/g'  /opt/python3/lib/python3.7/site-packages/djongo/introspection.py && \
    sed -i 's/.collection_names(include_system_collections=False)/.list_collection_names()/g'  /opt/python3/lib/python3.7/site-packages/djongo/base.py

ENV PYTHON3_ROOT_HOME=$PYTHON3_HOME
ENV _CI_COMMIT_SHORT_SHA="xxxxxxxx"
ENV MODULE_VERSION="xxxxxxxx"
ENV MODULE_INFO="xxxxxxxx"
ENV PRODUCT_ARCH="xxxxxxxx"

WORKDIR "$MODULE_DIR"